package it.e80.nm.bpm.model.entity;


import oracle.jbo.AttributeDef;
import oracle.jbo.AttributeList;
import oracle.jbo.Key;
import oracle.jbo.Row;
import oracle.jbo.RowIterator;
import oracle.jbo.RowSet;
import oracle.jbo.domain.DBSequence;
import oracle.jbo.domain.Date;
import oracle.jbo.domain.Number;
import oracle.jbo.server.AttributeDefImpl;
import oracle.jbo.server.EntityDefImpl;
import oracle.jbo.server.EntityImpl;
import oracle.jbo.server.SequenceImpl;
import oracle.jbo.server.SessionImpl;
import oracle.jbo.server.TransactionEvent;
// ---------------------------------------------------------------------
// ---    File generated by Oracle ADF Business Components Design Time.
// ---    Mon Apr 19 22:31:02 CEST 2010
// ---    Custom code may be added to this class.
// ---    Warning: Do not modify method signatures of generated methods.
// ---------------------------------------------------------------------
public class ProjectImpl extends BPMEntityImpl {
    
    private static EntityDefImpl mDefinitionObject;

    protected void markChanged() {
        for (int i = 0; i < ProjectImpl.AttributesEnum.values().length; i++) {
            //if (i != AttributesEnum.PrModifiedBy.index() && i != AttributesEnum.PrModifiedDate.index()) {
                setAttributeChanged(i, true);
            //}
            //setAttribute(AttributesEnum.PrModifiedBy.index(), AttributeDef.);
            //setAttribute(AttributesEnum.PrModifiedDate.index(), null);
        }
    }
    
    /**
     * AttributesEnum: generated enum for identifying attributes and accessors. Do not modify.
     */
    public enum AttributesEnum {
        PrId {
            public Object get(ProjectImpl obj) {
                return obj.getPrId();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrId((String)value);
            }
        }
        ,
        PrRevId {
            public Object get(ProjectImpl obj) {
                return obj.getPrRevId();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrRevId((Number)value);
            }
        }
        ,
        PrDescription {
            public Object get(ProjectImpl obj) {
                return obj.getPrDescription();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrDescription((String)value);
            }
        }
        ,
        PrModifiedDate {
            public Object get(ProjectImpl obj) {
                return obj.getPrModifiedDate();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrModifiedDate((Date)value);
            }
        }
        ,
        PrModifiedBy {
            public Object get(ProjectImpl obj) {
                return obj.getPrModifiedBy();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrModifiedBy((String)value);
            }
        }
        ,
        PrStatus {
            public Object get(ProjectImpl obj) {
                return obj.getPrStatus();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrStatus((Number)value);
            }
        }
        ,
        PrCustomerId {
            public Object get(ProjectImpl obj) {
                return obj.getPrCustomerId();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setPrCustomerId((String)value);
            }
        }
        ,
        Customer {
            public Object get(ProjectImpl obj) {
                return obj.getCustomer();
            }

            public void put(ProjectImpl obj, Object value) {
                obj.setCustomer((EntityImpl)value);
            }
        }
        ;
        private static AttributesEnum[] vals = null;
        private static int firstIndex = 0;

        public abstract Object get(ProjectImpl object);

        public abstract void put(ProjectImpl object, Object value);

        public int index() {
            return ProjectImpl.AttributesEnum.firstIndex() + ordinal();
        }

        public static int firstIndex() {
            return firstIndex;
        }

        public static int count() {
            return ProjectImpl.AttributesEnum.firstIndex() + ProjectImpl.AttributesEnum.staticValues().length;
        }

        public static AttributesEnum[] staticValues() {
            if (vals == null) {
                vals = ProjectImpl.AttributesEnum.values();
            }
            return vals;
        }
    }


    public static final int PRID = AttributesEnum.PrId.index();
    public static final int PRREVID = AttributesEnum.PrRevId.index();
    public static final int PRDESCRIPTION = AttributesEnum.PrDescription.index();
    public static final int PRMODIFIEDDATE = AttributesEnum.PrModifiedDate.index();
    public static final int PRMODIFIEDBY = AttributesEnum.PrModifiedBy.index();
    public static final int PRSTATUS = AttributesEnum.PrStatus.index();
    public static final int PRCUSTOMERID = AttributesEnum.PrCustomerId.index();
    public static final int CUSTOMER = AttributesEnum.Customer.index();

    /**
     * This is the default constructor (do not remove).
     */
    public ProjectImpl() {
    }


    /**
     * @return the definition object for this instance class.
     */
    public static synchronized EntityDefImpl getDefinitionObject() {
        if (mDefinitionObject == null) {
            mDefinitionObject = EntityDefImpl.findDefObject("it.e80.nm.bpm.model.entity.Project");
        }
        return mDefinitionObject;
    }

    /**
     * Gets the attribute value for PrId, using the alias name PrId.
     * @return the PrId
     */
    public String getPrId() {
        return (String)getAttributeInternal(PRID);
    }

    /**
     * Sets <code>value</code> as the attribute value for PrId.
     * @param value value to set the PrId
     */
    public void setPrId(String value) {
        setAttributeInternal(PRID, value);
    }

    /**
     * Gets the attribute value for PrDescription, using the alias name PrDescription.
     * @return the PrDescription
     */
    public String getPrDescription() {
        return (String)getAttributeInternal(PRDESCRIPTION);
    }

    /**
     * Sets <code>value</code> as the attribute value for PrDescription.
     * @param value value to set the PrDescription
     */
    public void setPrDescription(String value) {
        setAttributeInternal(PRDESCRIPTION, value);
    }

    /**
     * Gets the attribute value for PrModifiedDate, using the alias name PrModifiedDate.
     * @return the PrModifiedDate
     */
    public Date getPrModifiedDate() {
        return (Date)getAttributeInternal(PRMODIFIEDDATE);
    }


    /**
     * Sets <code>value</code> as the attribute value for PrModifiedDate.
     * @param value value to set the PrModifiedDate
     */
    public void setPrModifiedDate(Date value) {
        setAttributeInternal(PRMODIFIEDDATE, value);
    }

    /**
     * Gets the attribute value for PrModifiedBy, using the alias name PrModifiedBy.
     * @return the PrModifiedBy
     */
    public String getPrModifiedBy() {
        return (String)getAttributeInternal(PRMODIFIEDBY);
    }


    /**
     * Sets <code>value</code> as the attribute value for PrModifiedBy.
     * @param value value to set the PrModifiedBy
     */
    public void setPrModifiedBy(String value) {
        setAttributeInternal(PRMODIFIEDBY, value);
    }


    /**
     * Gets the attribute value for PrStatus, using the alias name PrStatus.
     * @return the PrStatus
     */
    public Number getPrStatus() {
        return (Number)getAttributeInternal(PRSTATUS);
    }


    /**
     * Sets <code>value</code> as the attribute value for PrStatus.
     * @param value value to set the PrStatus
     */
    public void setPrStatus(Number value) {
        setAttributeInternal(PRSTATUS, value);
    }

    /**
     * Gets the attribute value for PrCustomerId, using the alias name PrCustomerId.
     * @return the PrCustomerId
     */
    public String getPrCustomerId() {
        return (String)getAttributeInternal(PRCUSTOMERID);
    }

    /**
     * Sets <code>value</code> as the attribute value for PrCustomerId.
     * @param value value to set the PrCustomerId
     */
    public void setPrCustomerId(String value) {
        setAttributeInternal(PRCUSTOMERID, value);
    }


    /**
     * Gets the attribute value for PrRevId, using the alias name PrRevId.
     * @return the PrRevId
     */
    public Number getPrRevId() {
        return (Number)getAttributeInternal(PRREVID);
    }


    /**
     * Sets <code>value</code> as the attribute value for PrRevId.
     * @param value value to set the PrRevId
     */
    public void setPrRevId(Number value) {
        setAttributeInternal(PRREVID, value);
    }

    /**
     * getAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param attrDef the attribute

     * @return the attribute value
     * @throws Exception
     */
    protected Object getAttrInvokeAccessor(int index,
                                           AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            return AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].get(this);
        }
        return super.getAttrInvokeAccessor(index, attrDef);
    }

    /**
     * setAttrInvokeAccessor: generated method. Do not modify.
     * @param index the index identifying the attribute
     * @param value the value to assign to the attribute
     * @param attrDef the attribute

     * @throws Exception
     */
    protected void setAttrInvokeAccessor(int index, Object value,
                                         AttributeDefImpl attrDef) throws Exception {
        if ((index >= AttributesEnum.firstIndex()) && (index < AttributesEnum.count())) {
            AttributesEnum.staticValues()[index - AttributesEnum.firstIndex()].put(this, value);
            return;
        }
        super.setAttrInvokeAccessor(index, value, attrDef);
    }


    /**
     * @return the associated entity oracle.jbo.server.EntityImpl.
     */
    public EntityImpl getCustomer() {
        return (EntityImpl)getAttributeInternal(CUSTOMER);
    }

    /**
     * Sets <code>value</code> as the associated entity oracle.jbo.server.EntityImpl.
     */
    public void setCustomer(EntityImpl value) {
        setAttributeInternal(CUSTOMER, value);
    }

    /**
     * @param prId key constituent
     * @param prRevId key constituent

     * @return a Key object based on given key constituents.
     */
    public static Key createPrimaryKey(String prId, Number prRevId) {
        return new Key(new Object[]{prId, prRevId});
    }

    /**
     * Add attribute defaulting logic in this method.
     * @param attributeList list of attribute names/values to initialize the row
     */
    protected void create(AttributeList attributeList) {
        super.create(attributeList);
                SequenceImpl s =
                    new SequenceImpl("PR_REV_ID_SEQ", getDBTransaction());
                setAttribute("PrRevId", s.getSequenceNumber());
    }

    /**
     * Add entity remove logic in this method.
     */
    public void remove() {
        super.remove();
    }

    /**
     * Add locking logic here.
     */
    public void lock() {
        super.lock();
    }

    @Override
    protected void prepareForDML(int operation, TransactionEvent transactionEvent) {

        if (operation == DML_UPDATE) {
            //trova nuova sequence
            SequenceImpl s = new SequenceImpl("PR_REV_ID_SEQ", getDBTransaction());
            markChanged();
            setPrRevId(s.getSequenceNumber());
            setPrModifiedBy(((SessionImpl)getDBTransaction().getSession()).getUserPrincipalName());
            setPrModifiedDate(new Date(new java.sql.Date(new java.util.Date().getTime())));
            this.prepareForDML(DML_INSERT, transactionEvent);
        } else {
            super.prepareForDML(operation, transactionEvent);
        }
        
    }


    @Override
    protected void doDML(int operation, TransactionEvent transactionEvent) {
        if (operation == DML_UPDATE) {
            this.doDML(DML_INSERT, transactionEvent);
        } else {
            super.doDML(operation, transactionEvent);
        }
    }

    
    
}
